
import java.util.ArrayList;

public class DeviceManager {
	
	/****************************************
	 * Attributes
	 ****************************************/
	private ArrayList<Device> deviceList;
	
	// Output Devices
	public static final int LED = 114;
	public static final int VIBRATION_MOTOR = 92;
	public static final int BUZZER = 80;
	
	// Input Devices
	public static final int JOYSTICK = 42;
	public static final int LIGHT_SENSOR = 16;
	public static final int RESISTANCE_SENSOR = 48;
	public static final int ULTRASONIC_SENSOR = 138;
	
	
	/****************************************
	 * Constructor
	 ****************************************/
	public DeviceManager(iCATch316 iCatch) {
		
		deviceList = new ArrayList<Device>();
		
		// Initialize all devices
		deviceList.add(new LED(Device.LED, iCatch)); // Add LED
		deviceList.add(new VibrationMotor(Device.VIBRATION_MOTOR, iCatch)); // Add Vibration Motor
		deviceList.add(new Buzzer(Device.BUZZER, iCatch)); // Add Buzzer
		deviceList.add(new Joystick(Device.JOYSTICK, iCatch)); // Add Joystick
		deviceList.add(new LightSensor(Device.LIGHT_SENSOR, iCatch)); // Add Light Sensor
		deviceList.add(new ResistanceSensor(Device.RESISTANCE_SENSOR, iCatch)); // Add Resistance Sensor
		deviceList.add(new UltrasonicSensor(Device.ULTRASONIC_SENSOR, iCatch)); // Add Ultrasonic Sensor
	}
	
	// Methods	
	/****************************************
	 * Get all connected devices
	 ****************************************/
	public ArrayList<Device> getConnectedDevices() {
		return deviceList;
	}
	
	
	/****************************************
	 * Get a specific device by its type
	 ****************************************/
	public Device getDeviceByType(int type) {
		
		// Search through the deviceList, if found, return that Device
		for (int i=0; i < deviceList.size(); i++) {
			if (deviceList.get(i).address == type) {
				return deviceList.get(i);
			}
		}
		
		return null;
	}
}
